//
//  KWTButton.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/12/6.
//

#import "KWTButton.h"
@interface KWTButton()


@end
@implementation KWTButton

-(KWTButton*)initWithImage:(NSString*)image title:(NSString*)title
{
    if(self = [super init]){
        UIImage *btnImg = [UIImage imageNamed:image];
        UIImageView *imageView = [[UIImageView alloc]initWithImage:btnImg];
        [self addSubview:imageView];
        self.btnImageView = imageView;
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(@(CGSizeMake(btnImg.size.width, btnImg.size.height)));
            make.left.mas_offset(15);
            make.centerY.mas_offset(0);
        }];
        
        QMUILabel *btnTitleLab = [[QMUILabel alloc]init];
        btnTitleLab.text = title;
        btnTitleLab.numberOfLines = 2;
        btnTitleLab.adjustsFontSizeToFitWidth = YES;
        btnTitleLab.minimumScaleFactor = 0.5;
        [self addSubview:btnTitleLab];
        self.btnTitleLab = btnTitleLab;
        [btnTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_offset(0);
            make.left.equalTo(imageView.mas_right).offset(15);
            make.right.mas_offset(-3);
        }];
    }
   
    
    return self;
}

-(void)setImageMargin:(CGFloat)imageMargin
{
    _imageMargin = imageMargin;
    [_btnImageView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(imageMargin);
    }];
}

-(void)setImageTitleMargin:(CGFloat)imageTitleMargin
{
    _imageTitleMargin = imageTitleMargin;
    kWeakSelf;
    [_btnTitleLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.btnImageView.mas_right).offset(imageTitleMargin);
    }];
}

@end
